import React, {Component} from 'react';
import {PageContainer, ProForm, ProFormText, ProFormInstance} from "@ant-design/pro-components";
import {Card, Col, message, Row, Space} from "antd";
import {request} from "umi";
import {RegisterAPI} from "@/services/LoginApi";
import {response} from "express";
import {ServerMessages} from "@/services/ServerMessages";
import { useRef } from 'react';
import {ShowError} from "@/utils/format";
export default () => {

  const formRef = useRef<ProFormInstance>()

  return (
    <PageContainer title="注册用户">
      <Card>
        <ProForm
          formRef={formRef}
          onFinish={async (values) => {
            return new Promise(resolve => {
              const queryString = new URLSearchParams(values).toString()
              RegisterAPI(queryString).then(response => {
                if (response.status === 0) {
                  message.success(response.message)
                } else {
                  ShowError(response.message)
                }
                resolve(true)
              }, () => {
                ShowError(ServerMessages.error_message)
                resolve(false)
              })
            })
          }}
          submitter={{
            render: (props, doms) => {
              return (
                <Row>
                  <Col offset={0}>
                    <Space>{doms}</Space>
                  </Col>
                </Row>
              );
            },
            resetButtonProps: {
              style: {
                // 隐藏重置按钮
                display: 'none',
              },
            },
            submitButtonProps: {
              style: {
                marginLeft: '-8px'
              }
            },
          }}
        >
          <ProFormText
            width="md"
            name="username"
            label="账号"
            placeholder="1~13位a~z0~9字符"
          />
          <ProFormText.Password
            width="md"
            name="password"
            label="密码"
            placeholder="6~12位字符"
          />
          <ProFormText
            width="md"
            name="disciplinecode"
            label="学科代码"
            placeholder="4位数字"
          />
          <ProFormText
            width="md"
            name="jobnumber"
            label="工号"
            placeholder="1~13位字符"
          />
          <ProFormText
            width="md"
            name="phonenumber"
            label="手机号码"
            placeholder="11位数字"
          />
        </ProForm>
      </Card>
    </PageContainer>
  );
}
